package com.yfq.springframework.aop.framework;

import com.yfq.springframework.aop.AdvisedSupport;

/**
 * @author: yfq
 * @date: 2023/2/3 10:01
 * @description: 代理工厂，根据AdvisedSupport的proxyTargetClass来选择使用CglibAopProxy或者JdkDynamicAopProxy
 */
public class ProxyFactory {
    private final AdvisedSupport advised;

    public ProxyFactory(AdvisedSupport advised) {
        this.advised = advised;
    }

    public Object getProxy() {
        return createAopProxy().getProxy();
    }

    private AopProxy createAopProxy() {
        if (advised.isProxyTargetClass()) {
            return new CglibAopProxy(advised);
        }

        return new JdkDynamicAopProxy(advised);
    }
}
